using UnityEngine;
using System.Collections;

public enum TileCollision
{
	Passable = 0,
    Impassable = 1,
    Platform = 2,
	Exit = 3,
}

public class Tile : MonoBehaviour {
	
	public TileCollision tileCollision;
	public UISprite tileSprite;
	
	public Tile(string inputTileSprite, TileCollision inputTileCollision)
	{
		tileSprite.spriteName = inputTileSprite;
		tileCollision = inputTileCollision;
	}
	
	public Tile(string inputTileSprite, Color inputTileColor, TileCollision inputTileCollision)
	{
		tileSprite.spriteName = inputTileSprite;
		tileSprite.color = inputTileColor;
		
		tileCollision = inputTileCollision;
	}
	
	// Use this for initialization
	void Start()
	{
	
	}
	
	// Update is called once per frame
	void Update()
	{
	
	}
	
	public Rectangle GetBounds()
    {
		Transform rootTransform = transform;
		Transform spriteTransform = tileSprite.transform;
		return new Rectangle(rootTransform.localPosition.x + spriteTransform.localPosition.x, rootTransform.localPosition.y + spriteTransform.localPosition.y,
			spriteTransform.localScale.x, spriteTransform.localScale.y);
	}
	
	public void Init(char tileType)
	{
		switch (tileType)
        {
            // Blank space
    	    case '.':
				//tileSprite.spriteName = "Block";
				//tileSprite.color = new Color(1.0f, 1.0f, 1.0f, 0.0f);
				tileSprite.gameObject.SetActive(false);	
				tileCollision = TileCollision.Passable;
				return;
			case '#':
				//tileSprite.spriteName = "BorderBlock";
				tileCollision = TileCollision.Impassable;
				return;
			case 'X':
				//tileSprite.spriteName = "Block";
				tileSprite.color = new Color(0.0f, 0.0f, 0.0f, 1.0f);
				tileCollision = TileCollision.Passable;
				return;
			default:
				//tileSprite.spriteName = "Block";
				tileCollision = TileCollision.Passable;
				return;
		}
	}
	
	public void CopyFromTile(Tile targetTile)
	{
		tileSprite.spriteName = targetTile.tileSprite.spriteName;
		tileCollision = targetTile.tileCollision;
	}
}
